home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / import.tcl.z / import.tcl
Text File  |  2002-07-08  |  5KB  |  161 lines

  1. # import.tcl
  2. #
  3. # Import folders from other mail tools.
  4. #
  5. # Copyright (c) 1994 Xerox Corporation.
  6. # Use and copying of this software and preparation of derivative works based
  7. # upon this software are permitted. Any distribution of this software or
  8. # derivative works must comply with all applicable United States export
  9. # control laws. This software is made available AS IS, and Xerox Corporation
  10. # makes no warranty about the software, its performance or its conformity to
  11. # any specification.
  12.  
  13. proc Import_Init {} {
  14. }
  15.  
  16. proc Import_Dialog {} {
  17.     global _import
  18.     set w .import
  19.     if [Exwin_Toplevel $w "Import Tool" Import nobuttons] {
  20.     set f [Widget_Frame $w name Rim {top expand fill} -bd 10]
  21.     set _import(win,msg) [Widget_Message $f msg -width 250]
  22.     set f [Widget_Frame $f rim Rim {top expand fill} -bd 2 -relief raised]
  23.     Widget_Label $f label {left} -text "Mail Directory:"
  24.     set _import(win,entry) [Widget_Entry $f name {right fillx expand} -relief sunken]
  25.  
  26.     Widget_BindEntryCmd $_import(win,entry) <Return> [list ImportWhat $w]
  27.  
  28.     set f [Widget_Frame $w but Rim {top fill expand} -bd 10]
  29.     Widget_AddBut $f cancel "Cancel" "destroy $w" {left filly}
  30.     set _import(win,okbut) [Widget_AddBut $f ok "OK" [list ImportWhat $w] {right filly}]
  31.     }
  32.     catch {destroy .import.folders}
  33.     $_import(win,msg) config -text \
  34. "Import ucb-mailbox files into MH format.
  35. Enter mail directory and click OK."
  36.     focus $_import(win,entry)
  37. }
  38. proc ImportWhat { w } {
  39.     global _import mhProfile
  40.     set dir [string trim [$_import(win,entry) get]]
  41.     if {[string length $dir] == 0} {
  42.     Exmh_Status "Not a directory: $dir"
  43.     $_import(win,msg) config -text \
  44. "Please enter a mail directory and click OK."
  45.     return
  46.     }
  47.     set dir [glob -nocomplain $dir]
  48.     if ![file isdirectory $dir] {
  49.     Exmh_Status "Not a directory: $dir"
  50.     $_import(win,msg) config -text \
  51. "Not a directory: $dir
  52. Enter valid mail directory and click OK."
  53.     } elseif {[string compare $dir $mhProfile(path)] == 0} {
  54.     $_import(win,msg) config -text \
  55. "$dir clashes with default MH setting.
  56. You must quit exmh and change the Path:
  57. setting in your ~/.mh_profile file to a new directory."
  58.     } else {
  59.     $_import(win,msg) config -text \
  60. "(Un)Select folders to import and click Import.  You'll have to remove the old mail folders manually later."
  61.     set folders {}
  62.     set maxl 0
  63.     global _importlist
  64.     catch {unset _importlist}
  65.     foreach f [glob -nocomplain $dir/*] {
  66.         if [file isfile $f] {
  67.         set tail [file tail $f]
  68.         lappend folders $tail
  69.         if {[string length $tail] > $maxl} {
  70.             set maxl [string length $tail]
  71.         }
  72.         }
  73.     }
  74.     set col 3
  75.     set nframes [expr [llength $folders] / $col]
  76.     for {set i 0} {$i <= $nframes} {incr i} {
  77.         catch {destroy $w.but$i}
  78.         set f [Widget_Frame $w but$i]
  79.         for {set j 0} {$j < $col} {incr j} {
  80.         set next [lindex $folders 0]
  81.         if {[string length $next] == 0} {
  82.             break
  83.         }
  84.         set folders [lreplace $folders 0 0]
  85.         set b [Widget_CheckBut $f j$j $next _importlist($next) {right expand filly}]
  86.         $b config -onvalue $dir/$next -offvalue {} -width $maxl -anchor w
  87.         set _importlist($next) $dir/$next
  88.         }
  89.     }
  90.  
  91.     $_import(win,okbut) config -text Import -command ImportIt
  92.     set f [winfo parent $_import(win,okbut)]
  93.     catch {destroy $f.clear}
  94.     Widget_AddBut $f clear "Unselect All" [list ImportUnselectAll $f.clear]
  95.     }
  96. }
  97. proc ImportUnselectAll {button} {
  98.     global _importlist
  99.     foreach f [array names _importlist] {
  100.     set _importlist($f) {}
  101.     }
  102.     $button config -text "Select All" -command [list ImportSelectAll $button]
  103. }
  104. proc ImportSelectAll {button} {
  105.     global _importlist _import
  106.     set dir [glob -nocomplain [$_import(win,entry) get]]
  107.     foreach f [array names _importlist] {
  108.     set _importlist($f) $dir/$f
  109.     }
  110.     $button config -text "Unselect All" -command [list ImportUnselectAll $button]
  111. }
  112.  
  113. proc ImportIt {} {
  114.     global _importlist
  115.     set t [Help Import "Log of Import Actions"]
  116.     $t config -state normal -height 20
  117.     $t tag configure fixed -font fixed
  118.     foreach name [lsort [array names _importlist]] {
  119.     set f $_importlist($name)
  120.     if {[string length $f] != 0} {
  121.         global import
  122.         if [catch {glob $f} file] {
  123.         Exmh_Status $file
  124.         continue
  125.         }
  126.         Exmh_Status "inc +$name -file $file -notruncate"
  127.         $t insert end "inc +$name -file $file -notruncate" fixed
  128.         update idletasks
  129.         if [catch {
  130.         set in [open "|inc +$name -file $file -notruncate < /dev/null"]
  131.         fileevent $in readable [list ImportRead $in $t $name]
  132.         } result] {
  133.         $t insert end $result
  134.         catch {close $in}
  135.         }
  136.         $t see end
  137.         tkwait variable import($name)
  138.     }
  139.     }
  140.     $t config -state disabled
  141.     Flist_Refresh
  142.     destroy .import
  143. }
  144.  
  145. proc ImportRead {in t name} {
  146.     global import
  147.  
  148.     if [eof $in] {
  149.     catch {close $in}
  150.     set import($name) complete
  151.     return
  152.     }
  153.     if [catch {gets $in line} err] {
  154.     $t insert end $err\n
  155.     set import($name) complete
  156.     catch {close $in}
  157.     }
  158.     $t insert end $line\n
  159. }
  160.  
  161.